package org.droidcon.droidconapp;

import org.droidcon.droidconapp.news.NewsActivity;

import android.app.Activity;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

	private static final int GET_SCHEDULE_BOT = 1;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button bt = (Button) findViewById(R.id.news);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.important_dates);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.signup_conf);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.signup_camp);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.share);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.sponsors);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.program_conf);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.program_camp);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.location);
		bt.setOnClickListener(this);

		bt = (Button) findViewById(R.id.team);
		bt.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.news:
			Intent intent = new Intent(this, NewsActivity.class);
			startActivity(intent);
			break;
		case R.id.important_dates:
			intent = new Intent(this, ImportantDatesActivity.class);
			startActivity(intent);
			break;
		case R.id.signup_conf:
			intent = new Intent(Intent.ACTION_VIEW, Uri
					.parse(getString(R.string.uri_signup_conf)));
			startActivity(intent);
			break;
		case R.id.signup_camp:
			intent = new Intent(Intent.ACTION_VIEW, Uri
					.parse(getString(R.string.uri_signup_camp)));
			startActivity(intent);
			break;
		case R.id.share:
			intent = new Intent(Intent.ACTION_SEND);
			intent.setType("text/plain");
			intent.putExtra(Intent.EXTRA_SUBJECT,
					getString(R.string.share_subject));
			intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text));
			try {
				startActivity(intent);
			} catch (ActivityNotFoundException e) {
				Toast.makeText(this, R.string.nomailapp, Toast.LENGTH_SHORT)
						.show();
			}
			break;
		case R.id.sponsors:
			intent = new Intent(this, SponsorsActivity.class);
			startActivity(intent);
			break;
		case R.id.program_conf:
			intent = new Intent(this, ProgramActivity.class);
			startActivity(intent);
			break;
		case R.id.program_camp:			
			intent = new Intent(Intent.ACTION_MAIN);		
			intent.setClassName("org.scholt.mobile.schedulebot", "org.scholt.mobile.schedulebot.Splash");
			intent.putExtra("org.scholt.mobile.schedulebot.extras.EVENT_URL",
					"http://berlin.droidcamp.org");
			try {
				startActivity(intent);
			} catch (ActivityNotFoundException e) {
				showDialog(GET_SCHEDULE_BOT);
			}
			break;
		case R.id.location:
			intent = new Intent(Intent.ACTION_VIEW, Uri
					.parse(getString(R.string.uri_location)));
			try {
				startActivity(intent);
			} catch (ActivityNotFoundException e) {
				Toast.makeText(this, R.string.nomapapp, Toast.LENGTH_SHORT)
						.show();
			}
			break;
		case R.id.team:
			intent = new Intent(Intent.ACTION_VIEW, Uri
					.parse(getString(R.string.uri_team)));
			startActivity(intent);
			break;
		}

	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case GET_SCHEDULE_BOT:
			return new GetFromMarketDialog(this,
					R.string.schedule_bot_not_available,
					R.string.get_schedule_bot,
					R.string.schedule_bot_market_uri,
					R.string.schedule_bot_dev_uri);

		}
		return null;
	}

}